package com.snda.doodlepro.log;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.util.Log;

public class LogManager {

	private static String 		TAG 	= "LogManager";
	private List<LoggerBase> 	loggers = new ArrayList<LoggerBase>();
	private static LogManager 	logMgr  = null;
	
	public static void initialise(){
		if(logMgr == null){
			logMgr = new LogManager();
			logMgr.addLogger(new OutputLogger());
		}
		Log.d("tag", "LogManager initialise");
	}
	
	public static void log(String TAG, String function, String operation,
			String description) {
		initialise();
		
		Log.d("common", "function:" + function + " operation:" + operation + " description:" + description);
		
		for (Iterator iterator = logMgr.loggers.iterator(); iterator.hasNext();) {
			LoggerBase type = (LoggerBase) iterator.next();
			type.log(TAG, function, operation, description);
		}
	}
	
	public void addLogger(LoggerBase logger) {
		loggers.add(logger);
	}
	
	public static void terminate(){
		for (Iterator iterator = logMgr.loggers.iterator(); iterator.hasNext();) {
			LoggerBase type = (LoggerBase) iterator.next();
			type.terminate();
		}
		logMgr.loggers.clear();
	}
}
